package com.jinlejia.erp.ui.new_house.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.utils.StringUtil;

import java.util.ArrayList;
import java.util.Map;

/**
 * 加推
 */

public class AddRecommendAdapter extends YfListAdapter<Map<String,Object>> {

    public AddRecommendAdapter(ArrayList<Map<String,Object>> data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_add_remmond, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }
    @Override
    public RecyclerView.ViewHolder onCreateErrorViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.error_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        String areaTotal="",price="",houseType="",houseNumber="",date = "";
        Map<String, Object> map = mData.get(i);
        if (map.containsKey("areaTotal")) {
            if (!TextUtils.isEmpty(StringUtil.valueOf(map.get("areaTotal")))){
                areaTotal =StringUtil.valueOf(map.get("areaTotal")).concat("-");
            }
        }
        if (map.containsKey("houseType")){
            if (!TextUtils.isEmpty(StringUtil.valueOf(map.get("houseType")))){
                houseType = StringUtil.valueOf(map.get("houseType")).concat("-");
            }
        }
        if (map.containsKey("houseNumber")){
            if (!TextUtils.isEmpty(StringUtil.valueOf(map.get("houseNumber")))){
                houseNumber = StringUtil.valueOf(map.get("houseNumber")).concat("-");
            }
        }
        if (map.containsKey("date")){
             date = StringUtil.valueOf(map.get("date"));
        }
        if (map.containsKey("price")){
            price =  StringUtil.valueOf(map.get("price"));
        }
        if (!TextUtils.isEmpty(StringUtil.valueOf(map.get("price")))){
            ((ViewHolder) viewHolder).houseName.setText(houseNumber + houseType + areaTotal + price);
        }else {
            ((ViewHolder) viewHolder).houseName.setText(houseNumber + houseType + map.get("areaTotal"));
        }
        ((ViewHolder) viewHolder).day.setText(date);
        viewHolder.itemView.setTag(mData.get(i));
    }

    @Override
    public RecyclerView.ViewHolder onCreateLoadingViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.loading_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    private static final class ViewHolder extends RecyclerView.ViewHolder {

        //城市名
        TextView houseName;
        //日期
        TextView day;

        public ViewHolder(View itemView) {
            super(itemView);
            houseName = (TextView) itemView.findViewById(R.id.id_city_name);
            day = (TextView) itemView.findViewById(R.id.id_city_date);
        }
    }

}
